package jdbc;

import javax.xml.transform.Source;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class JdbcDemo7
{
    public static void main(String[] args)
    {
        Scanner scanner = new Scanner(System.in);
        System.out.println("name = "    );
        String name = scanner.nextLine();
        System.out.println("password = "   );
        String password = scanner.nextLine();
        System.out.println("nickname = ");
        String nickname = scanner.nextLine();
        try(Connection connection = DBUtil.getConnection())
        {
            String sql = "insert into userinfo1 (username,password,nickname) values (?,?,?)";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1,name);
            preparedStatement.setString(2,password);
            preparedStatement.setString(3,nickname);
            int i = preparedStatement.executeUpdate();
            if (i  > 0)
            {
                System.out.println("insert successfully");
            };
        }catch (SQLException e)
        {
            e.printStackTrace();
        }
    }
}
